//
//  BYJCarouselTableViewCell.m
//  BLDMusics
//
//  Created by 白云杰 on 16/3/17.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "BYJCarouselTableViewCell.h"

@interface BYJCarouselTableViewCell ()

@property (nonatomic, retain) UILabel *numberLabel;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *likesLabel;
@property (nonatomic, retain) UIImageView *likesImgView;
@property (nonatomic, retain) UIButton *MVButton;

@end

@implementation BYJCarouselTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createControls];
    }
    return self;
}

- (void)setModel:(BYJsongListModel *)model {
    _model = model;
    [self assignment];
}

- (void)createControls {
    
    self.numberLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_numberLabel];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLabel];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    
    self.likesLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_likesLabel];
    
    self.likesImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_likesImgView];
    
    self.MVButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_MVButton];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _numberLabel.frame = CGRectMake(10, 15, 30, 30);
    _numberLabel.textAlignment = NSTextAlignmentCenter;
    _numberLabel.text = [NSString stringWithFormat:@"%ld", (long)_indexPath];

    
    CGSize size = [APPTools labelRectWithSize:CGSizeMake(0, 30) labelText:_model.name Font:[UIFont systemFontOfSize:17]];
    _titleLabel.frame = CGRectMake(50, 5, size.width, 30);
    
    
    if (_model.mvListArr.count != 0) {
        
        _MVButton.frame = CGRectMake(60 + size.width, 0, 40, 40);
        [_MVButton setImage:[UIImage imageNamed:@"iconfont-mv"] forState:UIControlStateNormal];
        [_MVButton addTarget:self action:@selector(MVButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    } else {
        _MVButton.frame = CGRectMake(0, 0, 0, 0);
    }
    
    CGSize nameSize = [APPTools labelRectWithSize:CGSizeMake(0, 20) labelText:_model.singerName Font:[UIFont systemFontOfSize:15]];
    _nameLabel.frame = CGRectMake(50, 35, nameSize.width, 20);
    _nameLabel.font = [UIFont systemFontOfSize:15];
    
    _likesImgView.frame = CGRectMake(50 + nameSize.width + 10, 35, 20, 20);
    _likesImgView.image = [UIImage imageNamed:@"cell_favorite"];
    
    _likesLabel.frame = CGRectMake(90 + nameSize.width, 35, 50, 20);
    _likesLabel.font = [UIFont systemFontOfSize:15];
    
}

- (void)assignment {
    
    _titleLabel.text = _model.name;
    
    _nameLabel.text = _model.singerName;
    
    _likesLabel.text = [NSString stringWithFormat:@"%@", _model.favorites];
}

- (void)MVButtonAction:(UIButton *)button {
    
    
    BYJmvListModel *model = _model.mvListArr[0];
    
    if (_model.mvListArr.count != 0) {
        
        /** 调用block方法 */
        self.block(model);
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
